<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    



    <script>


    var  arr=[
  {
    "id": "1612691201767038978",
    "parentId": "0",
    "weight": 0,
    "name": "444444",
    "type": 0,
    "children": [
      {
        "id": "1612691604499914753",
        "parentId": "1612691201767038978",
        "weight": 0,
        "name": "44下的子目录",
        "type": 0,
        "children": [
          {
            "id": "1612777307351080962",
            "parentId": "1612691604499914753",
            "weight": 0,
            "name": "44下的2及目录",
            "type": 0,
            "children": [
              {
                "id": "1612777374527053825",
                "parentId": "1612777307351080962",
                "weight": 0,
                "name": "三级",
                "type": 0
              }
            ]
          }
        ]
      },
      {
        "id": "1612694495029682178",
        "parentId": "1612691201767038978",
        "weight": 0,
        "name": "44下的末级目录",
        "type": 1
      }
    ]
  }
]



var   obj={
    "id": "1612691201767038978",
    "parentId": "0",
    "weight": 0,
    "name": "444444",
    "type": 0,
    "children": [
      {
        "id": "1612691604499914753",
        "parentId": "1612691201767038978",
        "weight": 0,
        "name": "44下的子目录",
        "type": 0,
        "children": [
          {
            "id": "1612777307351080962",
            "parentId": "1612691604499914753",
            "weight": 0,
            "name": "44下的2及目录",
            "type": 0,
            "children": [
              {
                "id": "1612777374527053825",
                "parentId": "1612777307351080962",
                "weight": 0,
                "name": "三级",
                "type": 0
              }
            ]
          }
        ]
      },
      {
        "id": "1612694495029682178",
        "parentId": "1612691201767038978",
        "weight": 0,
        "name": "44下的末级目录",
        "type": 1
      }
    ]
  }


   
      function fn(item){
           console.log(item,'ssss');
             
       fn1(item)

      }

       function fn1(item){
         
        console.log(item.children);
       
        if(item.children.length>0){
          fn1(item.children)
        }else{
          console.log(22222222);
        }


       }


     arr.forEach((item)=>{
      fn(item)
     })

  

    </script>
</body>
</html>